package com.dayuanit.dy16.ebook.ebookweb.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class RabbitMqConfig {

    /**
     * 延迟队列
     * @return
     */
    @Bean
    public Queue delayQueue() {
        Queue delayQueue = QueueBuilder
                .durable()
                .withArgument("x-dead-letter-exchange", "deadDirectExchange")
                .withArgument("x-dead-letter-routing-key", "realyRootingKey")
                .withArgument("x-message-ttl", 20000)
                .build();

        return delayQueue;
    }

    /**
     * 实际消费的队列
     * @return
     */
    @Bean
    public Queue realyQueue() {
        return new Queue("realyQueue", true);
    }

    /**
     * 直连交换器
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("deadDirectExchange");
    }

    @Bean
    public Binding delayQueueBindExchange() {
        return BindingBuilder.bind(delayQueue()).to(directExchange()).with("delayRoutingKey");
    }

    @Bean
    public Binding realyQueueBindExchange() {
        return BindingBuilder.bind(realyQueue()).to(directExchange()).with("realyRootingKey");
    }

}
